<?php

class Skjb_Validate_Switch extends Zend_Validate_Abstract
{
    private $_validators = null;
    private $_notFoundPass = true;
    
    public function __construct(array $validators, $notFoundPass = true)
    {
        $this->_validators = $validators;
        $this->_notFoundPass = $notFoundPass;
    }
    
    public function isValid($value)
    {
        if (isset($this->_validators[$value])) {
            $validator = $this->_validators[$value];
        } elseif (isset($this->_validators['default'])) {
            $validator = $this->_validators['default'];
        } else {
            return $notFoundPass;
        }
        
        $valid = $validator->isValid($value);
        
        if (!$valid) {
            $this->_messages = $validator->getMessages();
            $this->_errors = $validator->getErrors();
        }
        
        return $valid;
    }
}
